﻿using System;
class ReplaceBit
{
    static void Main()
    {
        int testnumber=0;
        int newbit = 0;
        int smallmask = 0;
        int bigmask = 0;
        int counter=1;
        int position = 3;
        int numberandmask;
        int result=0;
        Console.Write("Input Number: ");
        while (true)
        {
            try
            {
                testnumber = int.Parse(Console.ReadLine());
                break;
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message + "\nPlease re-enter test number:");
            }
        }
        Console.WriteLine(Convert.ToString(testnumber, 2).PadLeft(32, '0'));
        Console.ReadLine();
        for (counter = 1; counter <= 3; counter++) 
        {
        smallmask = (1 << position);
        bigmask = (1 << position + 21);
        if (((testnumber & smallmask) >> position) == 1)
        {
            numberandmask = testnumber | smallmask;
            Console.WriteLine(Convert.ToString(smallmask, 2).PadLeft(32, '0'));
          //  Console.WriteLine(Convert.ToString(numberandmask, 2).PadLeft(32, '0'));

            result = testnumber | (smallmask << 21);
            Console.WriteLine(Convert.ToString(result, 2).PadLeft(32, '0'));
            Console.ReadLine();
        }
        else
        {
            smallmask = ~(smallmask);
            numberandmask = testnumber & smallmask;
            Console.WriteLine(Convert.ToString(smallmask, 2).PadLeft(32, '0'));
        //    Console.WriteLine(Convert.ToString(numberandmask, 2).PadLeft(32, '0'));

            result = testnumber & (smallmask << 21);
            Console.WriteLine(Convert.ToString(result, 2).PadLeft(32, '0'));
            Console.ReadLine();
        }  

        if (((testnumber & bigmask) >> position+21) == 1)
        {
            numberandmask = testnumber | bigmask;
            Console.WriteLine(Convert.ToString(bigmask, 2).PadLeft(32, '0'));
        //    Console.WriteLine(Convert.ToString(numberandmask, 2).PadLeft(32, '0'));

            result = testnumber | (bigmask >> 21);
            Console.WriteLine(Convert.ToString(result, 2).PadLeft(32, '0'));
            Console.ReadLine();
        }
        else
        {
            bigmask = ~(bigmask);
            numberandmask = testnumber & bigmask;
            Console.WriteLine(Convert.ToString(bigmask, 2).PadLeft(32, '0'));
           // Console.WriteLine(Convert.ToString(numberandmask, 2).PadLeft(32, '0'));

            result = testnumber & (bigmask >> 21);
            Console.WriteLine(Convert.ToString(result, 2).PadLeft(32, '0'));
            Console.ReadLine();
        }

        position++;
        }

      //  if (newbit == 0)
      //  {
         //   mask = ~(1 << bitposition);
        //    int numberandmask = testnumber & mask;
       //     Console.WriteLine(Convert.ToString(mask, 2).PadLeft(32, '0'));
       //     Console.ReadLine();
       //     Console.WriteLine(Convert.ToString(numberandmask, 2).PadLeft(32, '0'));
       //     Console.ReadLine();
      //  }
      //  else
      //  {
       //     mask = (1 << bitposition);
        //    int numberandmask = testnumber | mask;
        //    Console.WriteLine(Convert.ToString(mask, 2).PadLeft(32, '0'));
        //    Console.ReadLine();
        //    Console.WriteLine(Convert.ToString(numberandmask, 2).PadLeft(32, '0'));
        //    Console.ReadLine();
       // }
        Console.WriteLine(Convert.ToString(result, 2).PadLeft(32, '0'));
        Console.ReadLine();
    }
}

